package leetcode.周赛.第275场;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/9 13:07
 * @description：https://leetcode-cn.com/problems/check-if-every-row-and-column-contains-all-numbers/
 */
public class 检查是否每一行每一列都包含全部整数 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.checkValid(new int[][]{{1, 2, 3}, {3, 1, 2}, {2, 3, 1}}));
    }

    class Solution {
        public boolean checkValid(int[][] matrix) {
            int n = matrix.length;
            Set[] cols = new HashSet[n];
            for (int i = 0; i < cols.length; i++) {
                cols[i] = new HashSet<Integer>();
            }
            for (int[] nums : matrix) {
                Set<Integer> row = new HashSet<>();
                for (int j = 0; j < n; j++) {
                    if (!row.add(nums[j]) || !cols[j].add(nums[j])) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}



